package com.its.handle;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.its.domain.BaseResult;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
* 会员退出成功处理器
* */
public class MyMemberLogoutSuccessHandle implements LogoutSuccessHandler {
    @Resource
    private ObjectMapper objectMapper;

    @Override
    public void onLogoutSuccess(HttpServletRequest request,
                                HttpServletResponse response,
                                Authentication authentication) throws IOException {

        BaseResult<String> baseResult = new BaseResult<>(200, "退出成功", null);

        response.setContentType("application/json;charset=UTF-8");
        response.getOutputStream().write(objectMapper.writeValueAsBytes(baseResult));
    }

}
